import java.io.PrintStream;
import java.io.PrintWriter;


public class Statistics {
	public int correct;
	public int correctCaseInsensitive;
	public int inPositionLetters;
	public int correctLetters;
	
	public int totalWords;
	public int totalLetters;
	PrintStream out;
	public void update(String correctText, String predictedText) {
		// total number of words
		totalWords++;
		
		// correctly predicted words
		if (correctText.equals(predictedText)) {
			correct++;
		}
		
		// correctly predicted words (case insensitive)
		if (correctText.toLowerCase().equals(predictedText.toLowerCase())) {
			correctCaseInsensitive++;
		}
		
		// inPositionLetters
		totalLetters += correctText.length();
		for (int i=0; i<Math.min(correctText.length(), predictedText.length()); i++) {
			if (predictedText.charAt(i) == correctText.charAt(i)) {
				correctLetters++;
			}
		}
		
	}
	
	
	private void printLine(String s, int val) {
		out.printf("%-40s %4d", s, val);
		out.println();
	}
	private void printLine(String s, int val, int total) {
		out.printf("%-40s %4d/%-4d    %6.2f", s, val, total, 100.0*val/total);
		out.println("%");
	}
	
	
	public void printStatistics(PrintStream out) {
		this.out = out;
		out.println("------------------------------------------------------------------");
		printLine("Correct words:", correct, totalWords);
		printLine("Correct words (case insensitive):", correctCaseInsensitive, totalWords);
		printLine("In place letters:", correctLetters, totalLetters);
	}
	
}
